#ifndef IEC10X_PROTOCOL_H
#define IEC10X_PROTOCOL_H

typedef struct IEC10X_Protocol IEC10X_Protocol_T;

IEC10X_Protocol_T* IEC10X_Protocol_Create();
void IEC10X_Protocol_Destroy(IEC10X_Protocol_T* self);

void IEC10X_Protocol_SetIO(IEC10X_Protocol_T* self, 
    int (*read)(void* p, char* buf, int len), /*最多读len个字节的数据。返回值：<0:错误码；[0,len]:正确 */
    int (*write)(void* p, const char* buf, int len), /*最多写len个字节的数据。返回值：<0:错误码；[0,len]:正确*/
    int (*reset)(void* p), /*发生错误后用来重置*/
    void* priv /*p==priv*/
);

void IEC10X_Protocol_SetInterrupter(IEC10X_Protocol_T* self,
    int(*is_interrupted)(void* p), /*检测是否需要中断内部循环。返回值：1：中断；0：不中断*/
    void* priv
);

void IEC10X_Protocol_Run(IEC10X_Protocol_T* self);

#endif // IEC10X_PROTOCOL_H
